package com.zhaolang.qogir.ui.adapter.manage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhaolang.qogir.R;
import com.zhaolang.qogir.bean.ProductClassBean;
import com.zhaolang.qogir.util.ToastUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MangeProductClassifyAdapter extends BaseAdapter {
    @BindView(R.id.tv_class_name)
    TextView tvClassName;
    @BindView(R.id.btn_class_edit)
    TextView btnClassEdit;
    private Context mContext;
    private List<ProductClassBean> classList;
    private String TAG = "MangeProductClassifyAdapter";

    public MangeProductClassifyAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<ProductClassBean> classList) {
        this.classList = classList;
    }

    @Override
    public int getCount() {
        return classList != null ? classList.size() : 0;
    }

    @Override
    public ProductClassBean getItem(int position) {
        return classList != null && position >= 0 & position < classList.size() ? classList
                .get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ProductClassBean productClassBean = getItem(position);
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.manage_product_class_items, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (productClassBean.getProclassName().equals("")) {
            holder.tvClassName.setText(mContext.getResources().getText(R.string.ui_manage_string_unkown));
        } else {
            holder.tvClassName.setText(productClassBean.getProclassName());
        }
        holder.btnClassEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtils.showShort(mContext, "暂未支持");
            }
        });
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_class_name)
        TextView tvClassName;
        @BindView(R.id.btn_class_edit)
        TextView btnClassEdit;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
